#include "HY1C_out.h"
#include "l12_proto.h"
/*  W. Robinson, SAIC, 12 Aug 2011 add VIIRS scn_fmt, margin_s  */

void HY1C_cpl1rec(l1str *new, l1str *old)
{
    new->sensorID      = old->sensorID;
    new->npix          = old->npix;
    new->nscans        = old->nscans;
    new->spix          = old->spix;
    new->epix          = old->epix;
    new->dpix          = old->dpix;
    new->sscan         = old->sscan;
    new->escan         = old->escan;
    new->dscan         = old->dscan;
    new->nbands        = old->nbands;
    new->nbandsir      = old->nbandsir;
    new->ndets         = old->ndets;
    new->bindx         = old->bindx;
    new->length        = old->length;
    new->iscan         = old->iscan;
    new->detnum        = old->detnum;
    new->mside         = old->mside;
    new->n_inprods     = old->n_inprods;

    new->scn_fmt       = old->scn_fmt;
    new->margin_s      = old->margin_s;

    new->input         = old->input;

    new->landMaskOn    = old->landMaskOn;
    new->bathMaskOn    = old->bathMaskOn;
    new->cloudMaskOn   = old->cloudMaskOn;
    new->glintMaskOn   = old->glintMaskOn;
    new->hiltMaskOn    = old->hiltMaskOn;
    new->stlightMaskOn = old->stlightMaskOn;
    new->senzMaskOn    = old->senzMaskOn;
    new->solzMaskOn    = old->solzMaskOn;

    new->fsol          = old->fsol;
    new->tilt          = old->tilt;

    // 20180822
    // modify NBANDS to 8
    int nbadns = 8;

    memcpy(new->iwave, old->iwave, nbadns*sizeof(int32_t ));
    memcpy(new->fwave, old->fwave, nbadns*sizeof(float));
    memcpy(new->Fo,    old->Fo,    nbadns*sizeof(float));
    memcpy(new->Fobar, old->Fobar, nbadns*sizeof(float));
    memcpy(new->Fonom, old->Fonom, nbadns*sizeof(float));
    memcpy(new->Tau_r, old->Tau_r, nbadns*sizeof(float));
    memcpy(new->k_oz,  old->k_oz,  nbadns*sizeof(float));
    memcpy(new->aw,    old->aw,    nbadns*sizeof(float));
    memcpy(new->bbw,   old->bbw,   nbadns*sizeof(float));

    memcpy(new->data,old->data,new->length);


    memcpy(new->year,year_hy1c_tp ,sizeof(int32_t));
    memcpy(new->day,day_hy1c_tp ,sizeof(int32_t));
    memcpy(new->msec,old->msec,sizeof(int32_t));

    int npix = new->npix;
    int nbands = 8;//new->nbands;
    int nbandsir = 2;//new->nbandsir;
    memcpy(new->lon,old->lon,sizeof(float)*npix);
    memcpy(new->lat,old->lat,sizeof(float)*npix);
    memcpy(new->solz,old->solz,sizeof(float)*npix);
    memcpy(new->sola,old->sola,sizeof(float)*npix);
    memcpy(new->senz,old->senz,sizeof(float)*npix);
    memcpy(new->sena,old->sena,sizeof(float)*npix);

    memcpy(new->Lt,old->Lt,sizeof(float)*npix*nbands);
    memcpy(new->Lt_unc,old->Lt_unc,sizeof(float)*npix*nbands);

    memcpy(new->Ltir,old->Ltir,sizeof(float)*npix*nbandsir);
    memcpy(new->Bt,old->Bt,sizeof(float)*npix*nbandsir);

    memcpy(new->delphi,old->delphi,sizeof(float)*npix);
    memcpy(new->csolz,old->csolz,sizeof(float)*npix);
    memcpy(new->csenz,old->csenz,sizeof(float)*npix);
    memcpy(new->scattang,old->scattang,sizeof(float)*npix);

    memcpy(new->pixnum,old->pixnum,sizeof(int32_t)*npix);
    memcpy(new->nobs,old->nobs,sizeof(int32_t)*npix);

    memcpy(new->alpha,old->alpha,sizeof(float)*npix);
    memcpy(new->ws,old->ws,sizeof(float)*npix);
    memcpy(new->wd,old->wd,sizeof(float)*npix);
    memcpy(new->mw,old->mw,sizeof(float)*npix);
    memcpy(new->zw,old->zw,sizeof(float)*npix);
    memcpy(new->pr,old->pr,sizeof(float)*npix);
    memcpy(new->oz,old->oz,sizeof(float)*npix);
    memcpy(new->wv,old->wv,sizeof(float)*npix);
    memcpy(new->rh,old->rh,sizeof(float)*npix);
    memcpy(new->no2_tropo,old->no2_tropo,sizeof(float)*npix);
    memcpy(new->no2_strat,old->no2_strat,sizeof(float)*npix);
    memcpy(new->no2_frac,old->no2_frac,sizeof(float)*npix);
    memcpy(new->height,old->height,sizeof(float)*npix);
    memcpy(new->glint_coef,old->glint_coef,sizeof(float)*npix);
    memcpy(new->cloud_albedo,old->cloud_albedo,sizeof(float)*npix);
    memcpy(new->aerindex,old->aerindex,sizeof(float)*npix);
    memcpy(new->sstref,old->sstref,sizeof(float)*npix);
    memcpy(new->sssref,old->sssref,sizeof(float)*npix);
    memcpy(new->rho_cirrus,old->rho_cirrus,sizeof(float)*npix);

    memcpy(new->t_h2o,old->t_h2o,sizeof(float)*npix*nbands);
    memcpy(new->t_o2,old->t_o2,sizeof(float)*npix*nbands);
    memcpy(new->tg_sol,old->tg_sol,sizeof(float)*npix*nbands);
    memcpy(new->tg_sen,old->tg_sen,sizeof(float)*npix*nbands);
    memcpy(new->t_sol,old->t_sol,sizeof(float)*npix*nbands);
    memcpy(new->t_sen,old->t_sen,sizeof(float)*npix*nbands);
    memcpy(new->rhof,old->rhof,sizeof(float)*npix*nbands);
    memcpy(new->tLf,old->tLf,sizeof(float)*npix*nbands);
    memcpy(new->Lr,old->Lr,sizeof(float)*npix*nbands);
    memcpy(new->L_q,old->L_q,sizeof(float)*npix*nbands);
    memcpy(new->L_u,old->L_u,sizeof(float)*npix*nbands);
    memcpy(new->polcor,old->polcor,sizeof(float)*npix*nbands);
    memcpy(new->dpol,old->dpol,sizeof(float)*npix*nbands);
    memcpy(new->TLg,old->TLg,sizeof(float)*npix*nbands);
    memcpy(new->sw_n,old->sw_n,sizeof(float)*npix*nbands);
    memcpy(new->sw_a,old->sw_a,sizeof(float)*npix*nbands);
    memcpy(new->sw_bb,old->sw_bb,sizeof(float)*npix*nbands);
    memcpy(new->rhos,old->rhos,sizeof(float)*npix*nbands);

    memcpy(new->flags,old->flags,sizeof(int32_t )*npix);

    memcpy(new->ancqc,old->ancqc,sizeof(short)*npix);

    memcpy(new->mask,old->mask,sizeof(char )*npix);
    memcpy(new->hilt,old->hilt,sizeof(char )*npix);
    memcpy(new->cloud,old->cloud,sizeof(char )*npix);
    memcpy(new->glint,old->glint,sizeof(char )*npix);
    memcpy(new->land,old->land,sizeof(char )*npix);
    memcpy(new->swater,old->swater,sizeof(char )*npix);
    memcpy(new->ice,old->ice,sizeof(char )*npix);
    memcpy(new->solzmax,old->solzmax,sizeof(char )*npix);
    memcpy(new->senzmax,old->senzmax,sizeof(char )*npix);
    memcpy(new->stlight,old->stlight,sizeof(char )*npix);
    memcpy(new->absaer,old->absaer,sizeof(char )*npix);
    memcpy(new->navfail,old->navfail,sizeof(char )*npix);
    memcpy(new->navwarn,old->navwarn,sizeof(char )*npix);
    memcpy(new->darkpix,old->darkpix,sizeof(char )*npix);
    memcpy(new->filter,old->filter,sizeof(char )*npix);
    memcpy(new->cirrus,old->cirrus,sizeof(char )*npix);

    memcpy(new->pixdet,old->pixdet,sizeof(int32_t )*npix);
    memcpy(new->radcor,old->radcor,sizeof(float)*npix*nbands);

    int n_inprods = new->n_inprods;
    int i=0;
    for ( i = 0; i < n_inprods; i++ ) {
        memcpy(new->in_prods[i],old->in_prods[i],sizeof(float)*npix);
    }

    memcpy(new->in_flags,old->in_flags,sizeof(int32)*npix);


}

void cpl1rec(l1str *new, l1str *old)
{
    new->sensorID      = old->sensorID;
    new->npix          = old->npix;
    new->nscans        = old->nscans;
    new->spix          = old->spix;
    new->epix          = old->epix;
    new->dpix          = old->dpix;
    new->sscan         = old->sscan;
    new->escan         = old->escan;
    new->dscan         = old->dscan;
    new->nbands        = old->nbands;
    new->nbandsir      = old->nbandsir;
    new->ndets         = old->ndets;
    new->bindx         = old->bindx;
    new->length        = old->length;
    new->iscan         = old->iscan;
    new->detnum        = old->detnum;
    new->mside         = old->mside;
    new->n_inprods     = old->n_inprods;

    new->scn_fmt       = old->scn_fmt;
    new->margin_s      = old->margin_s;

    new->input         = old->input;

    new->landMaskOn    = old->landMaskOn;
    new->bathMaskOn    = old->bathMaskOn;
    new->cloudMaskOn   = old->cloudMaskOn;
    new->glintMaskOn   = old->glintMaskOn;
    new->hiltMaskOn    = old->hiltMaskOn;
    new->stlightMaskOn = old->stlightMaskOn;
    new->senzMaskOn    = old->senzMaskOn;
    new->solzMaskOn    = old->solzMaskOn;

    new->fsol          = old->fsol;
    new->tilt          = old->tilt;

    // 20180822
    // modify NBANDS to 8
    int nbadns = 8;

    memcpy(new->iwave, old->iwave, NBANDS*sizeof(int32_t ));
    memcpy(new->fwave, old->fwave, NBANDS*sizeof(float));
    memcpy(new->Fo,    old->Fo,    NBANDS*sizeof(float));
    memcpy(new->Fobar, old->Fobar, NBANDS*sizeof(float));
    memcpy(new->Fonom, old->Fonom, NBANDS*sizeof(float));
    memcpy(new->Tau_r, old->Tau_r, NBANDS*sizeof(float));
    memcpy(new->k_oz,  old->k_oz,  NBANDS*sizeof(float));
    memcpy(new->aw,    old->aw,    NBANDS*sizeof(float));
    memcpy(new->bbw,   old->bbw,   NBANDS*sizeof(float));

    memcpy(new->data,old->data,new->length);
}    

